import pygame,sys,os

class Gear(pygame.sprite.Sprite):
    def __init__(self, pos_x, pos_y,speed):
        super().__init__()
        self.image = pygame.image.load(self.resource_path("source/img/gear.png"))
        self.rect = self.image.get_rect()
        self.rect.bottomleft = (pos_x,pos_y)
        self.speed = speed
    def gear_move(self):

        self.rect.x += self.speed
        if self.rect.x >= 850:
            self.speed = -5
        elif self.rect.x <= 400:
            self.speed = 5

    def gear_person(self,person):
        if pygame.sprite.collide_rect(self,person):
            person.alive = False
    def Gear_display(self,window):
        window.blit(self.image,self.rect)
    def resource_path(self,relative_path):
        """ 根据打包后的环境动态加载资源路径 """
        if hasattr(sys, '_MEIPASS'):
            base_path = sys._MEIPASS
        else:
            base_path = os.path.abspath(".")
        return os.path.join(base_path, relative_path)